<%--
@author Nuwan Koggalahewa
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript">
    $(document).ready(function () {


        $('.land-table').dataTable({
            "sPaginationType": "full_numbers",
            "bDestroy": true,
            "oLanguage": {
                "sZeroRecords": $('#no-record').val(),
                "sLengthMenu": $('#display').val() + " _MENU_ " + $('#records').val(),
                "sSearch": $('#search').val(),
                //"sInfo":$('#showing').val() + " _START_ " + $('#to').val() + " _END_ " + $('#of').val() + " _TOTAL_ " + $('#entries').val(),
                "sInfo": "",
                "sInfoEmpty": $('#no-record').val(),
                "oPaginate": {
                    "sFirst": $('#first').val(),
                    "sLast": $('#last').val(),
                    "sNext": $('#next').val(),
                    "sPrevious": $('#previous').val()
                }

            },
            "fnDrawCallback": function () {
                if ($('.dataTables_paginate span span.paginate_button').size()) {
                    $('.dataTables_paginate')[0].style.display = "block";
                } else {
                    $('.dataTables_paginate')[0].style.display = "none";
                }
            },
            "aLengthMenu": [
                [ 10, 25, 50],
                [10, 25, 50]
            ],
            "iDisplayLength": 50

        });

        //Onclick View link
        /*    $('#viewLink').click(function () {

         });  */

        var type = '<s:property value="searchType"/>';

        //alert("searchType"+$("[name='searchType']").val());
        if ($("[name='pageNo']").val() != 0) {
            $('.navClass1').hide();
            $('.navClass2').hide();
            $('.navClass3').hide();
            $('.navClass4').hide();

            if (type == 1) {
                $('.navClass1').show();
            } else if (type == 2) {
                $('.navClass2').show();
            } else if (type == 3) {
                $('.navClass3').show();
            } else if (type == 4) {
                $('.navClass4').show();
            }


        }

    });


    $(function() {
        //Load text for Clear button
        $("#clearBtnId").val($("input#clearText").val()) ;
    });
    /* $(function() {
     $("#tree").treeview({
     collapsed: true,
     animated: "medium",
     control:"#sidetreecontrol",
     persist: "location"
     });
     });  */

    function viewLandDetails(landId) {
        //ajax find land list by parent id
        var url = '${"findClildrenByParentLand.do?landId=' + landId + '"}';
        $.get(url, $(this).serialize(), function (data) {
            $("#landDetails").html(data);
            //if list contain only one element display land details
            //else
            //display in tree
        });
    }

    function clearFields(){
        $("input#searchTextLandName1").val('');
        $("input#searchTextPlanNo").val('');
        $("input#searchTextLotNo").val('');
        $("input#searchTextHolderName").val('');
           }


    /*   var showMigrateData1;
       function handleMigrateRadio() {
           showMigrateData1 = $("input[name='migrateData']:checked").val();
           $('[name="showMigrateData"]').val(showMigrateData1);
           // alert($("#showMigrateData").val());
       }*/

</script>
<div id="land-registration-module-home-title" class="module-home-title">
    <s:a href="searchModule.do"><img src="${pageContext.request.contextPath}/images/search.png"
                                     alt="Land Alienation"><span><s:label
            value="%{getText('search.label')}"/></span></s:a>
    <span class="module-title-breaker"> > </span>
    <s:a href="searchAllLands.do"><img
            src="${pageContext.request.contextPath}/images/searchLand.png"><span><s:label
            value="%{getText('search_all_lands.label')}"/></span></s:a>
    <div id="back-button" align="right">
                <s:form><s:submit value="%{getText('back_btn.label')}" action="searchModule"/></s:form>
    </div>
</div>

<div class="page-title">
    <h2><s:label value="%{getText('search_all_lands.label')}"/></h2>
</div>
<div id="search-lands-form-outer">
    <table>
        <s:form name="searchAllLandBySearchText" id="searchAllLandBySearchText" method="POST" disabled="true">
        <tr>
                <td><s:label value="%{getText('name_of_land.label')}"/></td>
                <td><s:textfield name="searchText1" id="searchTextLandName1"/></td>
               <%-- <s:hidden name="searchType" value="1"/>--%>
                <s:hidden name="pageNo"/>
        </tr>
        <tr>
                <td><s:label value="%{getText('plan_no.label')}"/></td>
                <td><s:textfield name="searchText2" id="searchTextPlanNo"/></td>
        </tr>
        <tr>
                <td><s:label value="%{getText('lot_no.label')}"/></td>
                <td><s:textfield name="searchText3" id="searchTextLotNo"/></td>
        </tr>
        <tr>
                <td><s:label value="%{getText('holder_name.label')}"/></td>
                <td><s:textfield name="searchText4" id="searchTextHolderName"/></td>
        </tr>
    <tr>
        <table>

          <tr>
            <td >
                <s:submit action="searchAllLandBySearchText" value="%{getText('search.label')}"/>
            </td>
            <td>
                <s:if test="pageNo > 1">
                <s:submit action="searchAllLandUsingSearchTextBackPageId" name="back"
                          value="%{getText('previous.label')}"/>
               </s:if>
            </td>
            <td>
                <s:if test="showNextButton == true">
                <s:submit action="searchAllLandUsingSearchTextNextPageId" name="next"
                          value="%{getText('next.label')}"></s:submit>
                </s:if>
            </td>
            <td>
                <input type="button" id="clearBtnId" onclick="clearFields()"/>
            </td>
          </tr>
     </table>
    </tr>
    </s:form>
    </table>
</div>

<div id="landDetails">

</div>

<table id="land-table" class="width-100 margin-10-auto table land-table">
    <thead>
    <tr>
        <th><s:label value="%{getText('slmsSerialNumber.label')}"/></th>
        <th><s:label value="%{getText('name_of_the_land.label')}"/></th>
        <th><s:label value="%{getText('plan_no.label')}"/></th>
        <th><s:label value="%{getText('lot_no.label')}"/></th>
        <th><s:label value="%{getText('alienation_status.label')}"/></th>
        <th><s:label value="%{getText('approval_state.label')}"/></th>
        <th><s:label value="%{getText('action.label')}"/></th>

    </tr>
    </thead>
    <tbody>
    <s:iterator status="lands" value="landList">

        <tr>
                <%--<td width="130px"><s:if test="referenceNumber > 0"><s:property
                        value="referenceNumber"/></s:if><s:else><s:label
                        value="%{getText('undefined.label')}"/></s:else></td>--%>
            <td width="80px"><s:property value="id"/></td>
            <td><s:property value="nameOfTheLand"/></td>
            <td width="80px"><s:property value="planNumber"/></td>
            <td width="80px"><s:property value="lotNumber"/></td>
            <td width="180px">
                <s:if test="alienationState.ordinal() == 0">
                    <s:if test=" language=='si' ">
                        <s:property value="@lk.icta.common.AppConstants@UN_ALIENATED_SI"/>
                    </s:if>
                    <s:else>
                        <s:property value="alienationState"/>
                    </s:else>

                </s:if>
                <s:elseif test="alienationState.ordinal() == 1">
                    <s:if test=" language=='si' ">
                        <s:property value="@lk.icta.common.AppConstants@UN_ALIENATED_SI"/>
                    </s:if>
                    <s:else>
                        <s:property value="alienationState"/>
                    </s:else>

                </s:elseif>
                <s:else>
                    <s:property value="alienationState"/>
                </s:else>

            </td>
            <td>
                <s:property value="approvalState"/>

            </td>
            <td width="80px" class="center-align"><a href="#" title="View" id="viewLink"
                                                     onclick="viewLandDetails('<s:property value="id"/>')">
                <img src="${pageContext.request.contextPath}/images/detailed-form.png"
                     style="border:none; width:25px; height:25px;"/> </a></td>
        </tr>

    </s:iterator>
    </tbody>
</table>



<%--
<div id="sidetree">
    <div class="treeheader">&nbsp;</div>
    <div id="sidetreecontrol"><a href="?#">Collapse All</a> | <a href="?#">Expand All</a></div>

    <ul id="treettttt">
        <s:iterator status="lands" value="landList">
            <li><a href="?/index.cfm"><strong><s:property value="referenceNumber"/></strong></a>
                <ul>
                    <li><a href="?/enewsletters/index.cfm">Airdrie eNewsletters </a></li>
                </ul>
            </li>
        </s:iterator>
    </ul>
</div>  --%>


<%--<div id="landDetails">

</div>--%>

<%-- Localization text for data tables --%>
<s:hidden id="display" value="%{getText('display.label')}"/>
<s:hidden id="records" value="%{getText('records.label')}"/>
<s:hidden id="search" value="%{getText('search.label')}"/>
<s:hidden id="no-record" value="%{getText('no_record.label')}"/>
<s:hidden id="showing" value="%{getText('showing.label')}"/>
<s:hidden id="to" value="%{getText('to.label')}"/>
<s:hidden id="of" value="%{getText('of.label')}"/>
<s:hidden id="entries" value="%{getText('entries.label')}"/>
<s:hidden id="first" value="%{getText('first.label')}"/>
<s:hidden id="last" value="%{getText('last.label')}"/>
<s:hidden id="next" value="%{getText('next.label')}"/>
<s:hidden id="previous" value="%{getText('previous.label')}"/>
<s:hidden id="clearText" value="%{getText('clear.label')}" />
<s:hidden id="showNext" name="showNextButton"/>




